<link href="<?php echo CSS_User_URL; ?> /Profile_style.css" rel="stylesheet" type="text/css">    
<link href="<?php echo CSS_User_URL; ?> /Article_List_style.css" rel="stylesheet" type="text/css"> 

<section id="profile_cover" class="cover center-child">
    <div class="home_article">
        <div id="profile_image" class="image_parent">
            <img src="<?php echo Yii::app()->baseUrl; ?>/images/ProfileImage/<?php echo $NguoiDung->Avatar; ?>" alt="Ideawebsite.com"/>
            <div class="profile_function">
                <button class="button_base" id="btnKetBan"><span>Kết bạn</span></button>
                <button class="button_base" id="btnTheoDoi"><span>Theo dõi</span></button>
            </div>
        </div>
        <table id="profile_info">
            <?php
            if (!empty($NguoiDung->BiDanh) && !is_null($NguoiDung->BiDanh)) {
                ?>
                <tr>
                    <td colspan="2">
                        <h1 id="profile_info_name"><?php echo $NguoiDung->BiDanh; ?></h1>
                    </td>
                </tr>
                <?php
            }
            ?>

            <?php
            if (!empty($NguoiDung->Slogan) && !is_null($NguoiDung->Slogan)) {
                ?>
                <tr>
                    <td colspan="2">
                        <h2 id="profile_info_slogan"><?php echo $NguoiDung->Slogan; ?></h2>
                    </td>
                </tr>
                <?php
            }
            ?>

            <?php
            if (!empty($NguoiDung->NgaySinh) && !is_null($NguoiDung->NgaySinh)) {
                ?>
                <tr>
                    <td id="age_info" class="label_base">Tuổi: </td>
                    <td class="label_base"><?php
                        $NgaySinh = CDateTimeParser::parse($NguoiDung->NgaySinh, 'yyyy-MM-dd');
                        echo date('Y') - date('Y', $NgaySinh);
                        ?></td>
                </tr>
                <?php
            }
            ?>

            <?php
            if (!empty($NguoiDung->DiaChi) && !is_null($NguoiDung->DiaChi)) {
                ?>
                <tr>
                    <td id="location_info" class="label_base">Địa chỉ: </td>
                    <td class="label_base"><?php echo $NguoiDung->DiaChi; ?></td>
                </tr>
                <?php
            }
            ?>           
            <?php
            if (!empty($NguoiDung->NgayDangKy) && !is_null($NguoiDung->NgayDangKy)) {
                ?>
                <tr>
                    <td id="begin_info" class="label_base">Ngày tham gia: </td>
                    <td class="label_base"><?php
                        $NgayDangKy = CDateTimeParser::parse($NguoiDung->NgayDangKy, 'yyyy-MM-dd hh:mm:ss');
                        echo date('d - M - Y', $NgayDangKy);
                        ?></td>
                </tr>
                <?php
            }
            ?>     
            <?php
            if (!empty($NguoiDung->UyTin) && !is_null($NguoiDung->UyTin) && ($NguoiDung->UyTin > 0)) {
                ?>
                <tr>
                    <td id="reputation_info" class="label_base">Uy tín: </td>
                    <td>
                        <div id="reputation_bar">
                            <div class="reputation_value">
                                <div class="avalible_value" style="flex: <?php echo $NguoiDung->UyTin; ?>">
                                    <span><?php echo $NguoiDung->UyTin; ?></span>
                                </div>
                                <div class="another_value" style="flex: <?php echo 100 - $NguoiDung->UyTin; ?>">
                                    <span></span>
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>
                <?php
            }
            ?>  
        </table>

    </div>
</section>

<div class="home_wrapper" id="subContent">
    <h4><strong>Bài viết của <?php echo $NguoiDung->BiDanh; ?></strong></h4>    
    <div class="other_article">
        <?php echo $YTuongBiz; ?>
    </div>
</div>
<script>
    $(document).ready(function() {
        $.post('<?php echo Yii::app()->createUrl('User/CheckFriendAndFollow', array('Id' => $NguoiDung->Id)); ?>', {}, function(data) {
            if (data['IsFriend']) {
                $('#btnKetBan span').html('Hủy Kết bạn');
            } else {
                $('#btnKetBan span').html('Kết bạn');
            }
            if (data['IsFollow']) {
                $('#btnTheoDoi span').html('Hủy Theo dõi');
            } else {
                $('#btnTheoDoi span').html('Theo dõi');
            }
        }, 'json');
        $('#btnKetBan').click(function() {
            URL = '<?php echo Yii::app()->createUrl('User/FriendRequest', array('Id' => $NguoiDung->Id)); ?>';
            $.post(URL, {}, function(data) {
                if (data['Type'] === 'UNFRIEND') {
                    if (data['Result']) {
                        $('#btnKetBan span').html('Kết bạn');
                        $('#btnTheoDoi span').html('Theo dõi');
                    }
                } else if (data['Type'] === 'ADDFRIEND') {
                    if (data['Result']) {
                        $('#btnKetBan span').html('Hủy Kết bạn');
                        $('#btnTheoDoi span').html('Hủy Theo dõi');
                    }
                }
            }, 'json');
        });
        $('#btnTheoDoi').click(function() {
            URL = '<?php echo Yii::app()->createUrl('User/FollowPerson', array('Id' => $NguoiDung->Id)); ?>';
            $.post(URL, {}, function(data) {
                if (data['Type'] === 'UNFOLLOW') {
                    if (data['Result']) {
                        $('#btnTheoDoi span').html('Theo Dõi');
                    }
                } else if (data['Type'] === 'FOLLOW') {
                    if (data['Result']) {
                        $('#btnTheoDoi span').html('Hủy Theo Dõi');
                    }
                }
            }, 'json');
        });
    });
</script>